package com.sunnyatwal.kettlebell;

import java.util.ArrayList;

import com.sunnyatwal.kettlebell.model.Exercise;

import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ExerciseAdapter extends ArrayAdapter<Exercise>{

    private Context mContext; 
    private int mLayoutResourceId;    
    //private ArrayList<Exercise> mData;
    
    
    static class ExerciseHolder {
        TextView txtTitle;
    }
    
    
    public ExerciseAdapter(Context context, int layoutResourceId, ArrayList<Exercise> data) {
    	
        super(context, layoutResourceId, data);
        mLayoutResourceId = layoutResourceId;
        mContext = context;
        //mData = data;
    }

    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    	
        View row = convertView;
        ExerciseHolder holder = null;
        
        if(row == null) {
        	
            LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
            row = inflater.inflate(mLayoutResourceId, parent, false);
            
            holder = new ExerciseHolder();
            holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);            
            row.setTag(holder);
        }
        else {
            holder = (ExerciseHolder)row.getTag();
        }
        
        Exercise exercise = getItem(position);
        
        //TODO: update fonts globally, not just here
        Typeface tfTitle = Typeface.createFromAsset(row.getResources().getAssets(), "fonts/Roboto-Regular.ttf");
        holder.txtTitle.setTypeface(tfTitle);
        holder.txtTitle.setText(exercise.getTitle());
                
        return row;
    }
    
    
}